package com.znyj.cloud.device.service;

import com.znyj.cloud.device.dao.TaskDao;
import com.znyj.cloud.device.entity.TaskEntity;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by gaoliwei02 on 17/6/3.
 */
@Service
public class TaskService {
    private static final Logger logger = Logger.getLogger(TaskService.class);

    @Autowired
    private TaskDao taskDao;

    public int insertTask(TaskEntity taskEntity) {
        return taskDao.insert(taskEntity);
    }

    public int updateTask(TaskEntity taskEntity) {
        return taskDao.update(taskEntity);
    }

    public int findByOrderIdAndUpdateStatusWithExecute(String executeResult, long orderId, int sendStatus) {
        return taskDao.findByOrderIdAndUpdateStatusWithExecute(executeResult, orderId, sendStatus);
    }

    public int findByOrderIdAndUpdateStatus(long orderId, int sendStatus) {
        return taskDao.findByOrderIdAndUpdateStatus(orderId, sendStatus);
    }

    public TaskEntity findByOrderId(long orderId) {
        return taskDao.findByOrderId(orderId);
    }

    public long findNewestOrderId() {
        long orderId;
        try {
            orderId = taskDao.findNewestOrderId();
        } catch (Exception e) {
            orderId = 0;
            logger.error("findNewestOrderId get orderId null!");
        }
        return orderId;
    }
}
